package com.fujimana.android.manacode.converter.impl;

import java.util.ArrayList;
import java.util.List;

import com.fujimana.android.manacode.converter.BaseConverter;
import com.fujimana.android.manacode.converter.Decorator;
import com.fujimana.android.manacode.converter.Options;
import com.fujimana.android.manacode.converter.TokenMatcher;
import com.fujimana.android.manacode.converter.token.CommentToken;
import com.fujimana.android.manacode.converter.token.WordToken;

public class JavaConverter extends BaseConverter {

	static final String[] KEY_WORD = { "abstract", "boolean", "break", "byte",
			"case", "catch", "char", "class", "const", "continue", "default",
			"do", "double", "else", "extends", "final", "finally", "float",
			"for", "goto", "if", "implements", "import", "instanceof", "int",
			"interface", "long", "native", "new", "package", "private",
			"protected", "public", "return", "short", "static", "strictfp",
			"super", "switch", "synchronized", "this", "throw", "throws",
			"transient", "try", "void", "volatile", "while", "widefp", "true",
			"false", "null", };

	private List<TokenMatcher> matchers = new ArrayList<TokenMatcher>();

	public JavaConverter(Options options) {
		super(options);
		this.matchers = new ArrayList<TokenMatcher>();
		
		this.matchers.add(new SlashComentMatcher(getOptions()));
		this.matchers.add(new SlashStarComentMatcher(getOptions()));

		getDecorate().put(WordToken.TYPE, new JavaKeywordDecorator());
		getDecorate().put(CommentToken.TYPE, CommentToken.DECORATE);
	}

	@Override
	public List<TokenMatcher> getTokenMatchers() {
		return this.matchers;
	}

	class JavaKeywordDecorator implements Decorator {

		@Override
		public String decorate() {
			return "color: #800000;";
		}

		@Override
		public boolean isDecorate(String value) {
			return isKeyword(value);
		}

		public boolean isKeyword(String word) {

			for (String str : KEY_WORD) {
				if (str.equals(word)) {
					return true;
				}
			}

			return false;
		}

	}
}
